package io.persimmon.core.exception;

import ch.qos.logback.classic.Level;
import io.persimmon.core.dto.ResponseCode;
import io.persimmon.core.module.id.DefaultIDFactory;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.UUID;

@Data
@Slf4j
public class PersimmonException extends RuntimeException {
    private String id = DefaultIDFactory.UUID.createId();
    private String message;
    private Level level = Level.WARN;
    private Object[] data;
    private ResponseCode rResponseCode;
    private String alertMessage;

    public PersimmonException(String message) {
        super(message);
        this.message = message;
        this.id = UUID.randomUUID().toString();
    }

    public PersimmonException(Throwable t) {
        super(t);
        this.id = UUID.randomUUID().toString();
    }


    public PersimmonException level(Level level) {
        this.level = level;
        return this;
    }

    public PersimmonException data(Object... data) {
        this.data = data;
        return this;
    }

    public PersimmonException responseCode(ResponseCode beeResponseCode) {
        this.rResponseCode = beeResponseCode;
        return this;
    }

    public PersimmonException alertMessage(String alertMessage) {
        this.alertMessage = alertMessage;
        return this;
    }

    public PersimmonException exceptionId(String exceptionId) {
        if (StringUtils.isNotEmpty(exceptionId)) {
            this.id = exceptionId;
        }
        return this;
    }
}
